package xiao.ke.sbdemo.controller;/**
 * @author XuXiaoK
 * @create 2019-11-26 21:49
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xiao.ke.sbdemo.job.AsyncTask;

import java.util.concurrent.Future;

/**
 *@Author XiaoKe
 *@Date 2019/11/26 21:49
 *@Description TODO
 */
@RestController
@RequestMapping("/api/v1")
public class AsyncController {

    @Autowired
    private AsyncTask task;

    @GetMapping("async_task")
    public void task() throws InterruptedException {
        long begin = System.currentTimeMillis();

//		task.task1();
//		task.task2();

        Future<String> task4 = task.task4();
        Future<String> task5 = task.task5();
        for(;;){
            if (task4.isDone() && task5.isDone()) {
                break;
            }
        }


        long end = System.currentTimeMillis();

        long total = end-begin;
        System.out.println("执行总耗时="+total);
    }
}
